﻿@model AddressModel
@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script>
        $(document).ready(function() {
            $("#@Html.IdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.IdFor(model => model.StateProvinceId)");
                $.ajax({
                    cache: false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Home"))",
                    data: { "countryId": selectedItem, "addSelectStateItem": "false" },
                    success: function(data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                    },
                    error: function(xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                    }
                });
            });
        });
    </script>
}
<input asp-for="Id" type="hidden"/>
<input asp-for="FirstNameEnabled" type="hidden"/>
<input asp-for="FirstNameRequired" type="hidden"/>
<input asp-for="LastNameEnabled" type="hidden"/>
<input asp-for="LastNameRequired" type="hidden"/>
<input asp-for="EmailEnabled" type="hidden"/>
<input asp-for="EmailRequired" type="hidden"/>
<input asp-for="CompanyEnabled" type="hidden"/>
<input asp-for="CompanyRequired" type="hidden"/>
<input asp-for="VatNumberEnabled" type="hidden"/>
<input asp-for="VatNumberRequired" type="hidden"/>
<input asp-for="CountryEnabled" type="hidden"/>
<input asp-for="StateProvinceEnabled" type="hidden"/>
<input asp-for="CityEnabled" type="hidden"/>
<input asp-for="CityRequired" type="hidden"/>
<input asp-for="StreetAddressEnabled" type="hidden"/>
<input asp-for="StreetAddressRequired" type="hidden"/>
<input asp-for="StreetAddress2Enabled" type="hidden"/>
<input asp-for="StreetAddress2Required" type="hidden"/>
<input asp-for="ZipPostalCodeEnabled" type="hidden"/>
<input asp-for="ZipPostalCodeRequired" type="hidden"/>
<input asp-for="PhoneEnabled" type="hidden"/>
<input asp-for="PhoneRequired" type="hidden"/>
<input asp-for="FaxEnabled" type="hidden"/>
<input asp-for="FaxRequired" type="hidden"/>
<input asp-for="NoteEnabled" type="hidden"/>

<div class="form-horizontal">
    <div class="form-body">
        @if (Model.NameEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="Name"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Name"/>
                    <span asp-validation-for="Name"></span>
                </div>
            </div>
        }
        @if (Model.FirstNameEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="FirstName"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="FirstName"/>
                    <span asp-validation-for="FirstName"></span>
                </div>
            </div>
        }
        @if (Model.LastNameEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="LastName"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="LastName"/>
                    <span asp-validation-for="LastName"></span>
                </div>
            </div>
        }
        @if (Model.EmailEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="Email"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Email"/>
                    <span asp-validation-for="Email"></span>
                </div>
            </div>
        }
        @if (Model.CompanyEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="Company"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Company"/>
                    <span asp-validation-for="Company"></span>
                </div>
            </div>
        }
        @if (Model.VatNumberEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="VatNumber"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="VatNumber"/>
                    <span asp-validation-for="VatNumber"></span>
                </div>
            </div>
        }
        @if (Model.CountryEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="CountryId"/>
                <div class="col-md-9 col-sm-9">
                    <admin-select asp-for="CountryId" asp-items="Model.AvailableCountries"/>
                    <span asp-validation-for="CountryId"></span>
                </div>
            </div>
        }
        @if (Model.CountryEnabled && Model.StateProvinceEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="StateProvinceId"/>
                <div class="col-md-9 col-sm-9">
                    <admin-select asp-for="StateProvinceId" asp-items="Model.AvailableStates"/>
                    <span asp-validation-for="StateProvinceId"></span>
                </div>
            </div>
        }
        @if (Model.CityEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="City"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="City"/>
                    <span asp-validation-for="City"></span>
                </div>
            </div>
        }
        @if (Model.StreetAddressEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="Address1"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Address1"/>
                    <span asp-validation-for="Address1"></span>
                </div>
            </div>
        }
        @if (Model.StreetAddress2Enabled)
        {
            <div class="form-group">
                <admin-label asp-for="Address2"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Address2"/>
                    <span asp-validation-for="Address2"></span>
                </div>
            </div>
        }
        @if (Model.ZipPostalCodeEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="ZipPostalCode"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="ZipPostalCode"/>
                    <span asp-validation-for="ZipPostalCode"></span>
                </div>
            </div>
        }
        @if (Model.PhoneEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="PhoneNumber"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="PhoneNumber"/>
                    <span asp-validation-for="PhoneNumber"></span>
                </div>
            </div>
        }
        @if (Model.FaxEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="FaxNumber"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="FaxNumber"/>
                    <span asp-validation-for="FaxNumber"></span>
                </div>
            </div>
        }
        @if (Model.NoteEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="Note"/>
                <div class="col-md-9 col-sm-9">
                    <admin-input asp-for="Note"/>
                    <span asp-validation-for="Note"></span>
                </div>
            </div>
        }
        @if (Model.AddressTypeEnabled)
        {
            <div class="form-group">
                <admin-label asp-for="AddressType"/>
                <div class="col-md-9 col-sm-9">
                    <select asp-for="AddressType" asp-items="EnumTranslationService.ToSelectList(AddressType.Any, false).ToList()" class="form-control custom-select"></select>
                    <span asp-validation-for="AddressType"></span>
                </div>
            </div>
        }
        @if (Model.CustomAddressAttributes.Count > 0)
        {
            <partial name="Partials/AddressAttributes" model="Model.CustomAddressAttributes"/>
        }
    </div>
</div>